package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape;

import java.util.Collection;


class ShapePatternHelper {
    static void checkShapePattern(Collection<ShapeElement> elements) throws InvalidShapeException {
        int minTotalCardsCount = 0;
        int maxTotalCardsCount = 0;
        for (ShapeElement element : elements) {
            if (element instanceof WildcardShapeElement) {
                maxTotalCardsCount += 13;
            } else if (element instanceof ExactShapeElement) {
                ExactShapeElement exact = (ExactShapeElement) element;
                minTotalCardsCount += exact.getCardsCount();
                maxTotalCardsCount += exact.getCardsCount();
            } else {
                IntervalShapeElement interval = (IntervalShapeElement) element;
                minTotalCardsCount += interval.getMinCardsCount();
                maxTotalCardsCount += interval.getMaxCardsCount();
            }

        }
        if (minTotalCardsCount > 13 || maxTotalCardsCount < 13) {
            throw new InvalidShapeException();
        }
    }
}
